<template>
  <div class="follow">
    <!-- 头部导航栏 -->
    <van-nav-bar title="动态">
      <template #left>
        <span class="iconfont icon-gengduo1" @click="menu"></span>
      </template>
      <template #right>
        <span class="iconfont icon-jiahao2fill" @click="more"></span>
      </template>
    </van-nav-bar>
    <!-- 关注 -->
    <div class="follow-list">
      <div>
        <img src="../../assets/quanzi.jpg" alt="" />
        <p>我的圈子</p>
      </div>
      <div class="list">
        <div
          class="aaa"
          v-for="(data, index) in list1"
          :key="data.userId"
          @click="goSinger(index)"
        >
          <img :src="data.avatarUrl" alt="" />
          <p>{{ data.nickname }}</p>
        </div>

        <div @click="goFriend()">
          <span class="iconfont icon-gengduo"></span>
          <!-- <img src="../../assets/quanzi.jpg" alt="" /> -->
          <p>全部好友</p>
        </div>
      </div>
    </div>
    <!-- 我的关注 -->
    <div class="follow-all">
      <div class="head">
        <div class="left">
          <p>我的关注</p>
        </div>
        <div class="right">
          <ul>
            <li
              :class="current === index ? 'active' : ''"
              v-for="(data, index) in list"
              @click="handleChange(index)"
              :key="index"
            >
              {{ data }}
            </li>
          </ul>
        </div>
      </div>
      <div v-show="han" class="zong">
        <div class="share" v-for="(item, index) in one" :key="index">
          <!-- 发布人信息 -->
          <div class="message">
            <div @click="goSinger(index)">
              <img v-if="item" :src="item.value.avatarUrl" alt="" />
            </div>
            <div class="name">
              <span>{{ item.value.nickname }}</span>
              <img v-show="lev" src="../../assets/level.jpg" alt="" />
              <span v-show="lev" class="levels">贰</span>
              <span class="song">&nbsp;分享歌单：</span>
              <p class="releaseTime" v-if="item.name[0]">
                {{ item.name[0].eventTime | formatDates }}
              </p>
            </div>
          </div>
          <!-- 发布内容 -->
          <div class="content" v-if="item.name[0]">
            <p>
              {{ item.name[0].json.msg }}
            </p>
            <p class="iconfont icon-lianjie">
              <a href="#">网页链接</a>
            </p>
            <div class="picture"></div>
            <div class="son" @click="play(item.name[0].json.song.id)">
              <img
                v-if="item.name[0].json.song"
                :src="item.name[0].json.song.img80x80"
                alt=""
              />
              <img
                v-if="!item.name[0].json.song"
                src="http://p1.music.126.net/Re66e_s1e7nRcH-dfHgZrg==/109951167090331688.jpg"
                alt=""
              />

              <div>
                <p v-if="item.name[0].json.song">
                  {{ item.name[0].json.song.name }}
                </p>
                <!-- <p v-if="!item.name[0].json.song">11</p> -->
                <p v-if="!item.name[0].json.song">{{ item.value.signature }}</p>
                <p v-if="item.name[0].json.song">
                  by&nbsp;{{ item.name[0].json.song.album.name }}
                </p>
                <p v-if="!item.name[0].json.song">by&nbsp;韩梦祥</p>
              </div>
            </div>
          </div>
        </div>
        <p class="end" v-if="hhh">嘀嘀嘀——正在加载中</p>
        <p class="end" v-if="!hhh">抱歉没有更多内容啦</p>
      </div>
      <div v-show="han1" class="zong">
        <div class="share" v-for="(item, index) in two" :key="index">
          <!-- 发布人信息 -->
          <div class="message">
            <div><img :src="item.value.avatarUrl" alt="" /></div>
            <div class="name">
              <span>{{ item.value.nickname }}</span>
              <img v-show="lev" src="../../assets/level.jpg" alt="" />
              <span v-show="lev" class="levels">贰</span>
              <span class="song">&nbsp;分享歌单：</span>
              <p class="releaseTime" v-if="item.name[0]">
                {{ item.name[0].eventTime | formatDates }}
              </p>
            </div>
          </div>
          <!-- 发布内容 -->
          <div class="content">
            <p>
              {{ item.name[0].json.msg }}
            </p>
            <p class="iconfont icon-lianjie">
              <a href="#">网页链接</a>
            </p>
            <div class="picture"></div>
            <div class="son" @click="play(item.name[0].json.song.id)">
              <img
                v-if="item.name[0].json.song"
                :src="item.name[0].json.song.img80x80"
                alt=""
              />
              <img
                v-if="!item.name[0].json.song"
                src="http://p1.music.126.net/Re66e_s1e7nRcH-dfHgZrg==/109951167090331688.jpg"
                alt=""
              />

              <div>
                <p v-if="item.name[0].json.song">
                  {{ item.name[0].json.song.name }}
                </p>
                <!-- <p v-if="!item.name[0].json.song">11</p> -->
                <p v-if="!item.name[0].json.song">{{ item.value.signature }}</p>
                <p v-if="item.name[0].json.song">
                  by&nbsp;{{ item.name[0].json.song.album.name }}
                </p>
                <p v-if="!item.name[0].json.song">by&nbsp;韩梦祥</p>
              </div>
            </div>
          </div>
        </div>
        <p class="end" v-if="hhh">嘀嘀嘀——正在加载中</p>
        <p class="end" v-if="!hhh">抱歉没有更多内容啦</p>
      </div>
      <div v-show="han2" class="zong">
        <p class="friend">可怜的你并没有朋友啊</p>
      </div>
      <!-- <p class="end" v-if="hhh">嘀嘀嘀——正在加载中</p>
      <p class="end" v-if="!hhh">抱歉没有更多内容啦</p> -->
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import "../../assets/font-follow/vantChange.css";
import { setToken } from "@/utils/auth";
import axios from "axios";
import { formatDate } from "./filters.js";
export default {
  data() {
    return {
      active: 0,
      list: ["全部", "音乐人", "朋友"],
      current: 0,
      current1: 0,
      list1: [],
      list2: [],
      list3: [],
      pic: [],
      time: [],
      one: [],
      two: [],
      // san: [],
      han: true,
      han1: false,
      han2: false,
      lev: false,
      id: "",
      hhh: true,
    };
  },
  computed: {
    param() {
      return `cookie=${localStorage.getItem(
        "cookie"
      )}&timestamp=${new Date().getTime()}`;
    },
  },
  watch: {},

  filters: {
    formatDates(time) {
      var data = new Date(time);
      return formatDate(data, "yyyy-MM-dd");
    },
  },

  methods: {
    play(id) {
      this.$router.push("/playpage/" + id);
    },
    goFriend() {
      this.$router.push("/allfriends");
    },
    goSinger(index) {
      const id = this.list2[index];
      // console.log(id);
      this.$router.push("/singerhomepage/" + id);
    },
    menu() {
      Toast("返回");
      setToken(
        "df69a51f24b2ed15d4d0bbd34bed9600f0c51052a558e8ce14ec088832aed9fd519e07624a9f0053d78b6050a17a35e705925a4e6992f61d07c385928f88e8de"
      );
    },
    more() {
      Toast("按钮");
    },
    handleChange(index) {
      this.current = index;
      if (index == 0) {
        this.han = true;
        this.han1 = this.han2 = false;
      } else if (index == 1) {
        this.han1 = true;
        this.han = this.han2 = false;
      } else {
        this.han2 = true;
        this.han = this.han1 = false;
      }
    },
    //调取接口获取用户信息
    async user() {
      const res = await axios.get(
        "http://192.168.31.27:3000/user/account?" + this.param,
        {
          withCredentials: true,
        }
      );
      const id = res.data.account.id;

      //调取接口获取用户关注列表
      const result = await axios.get(
        "http://192.168.31.27:3000/user/follows",
        {
          params: {
            uid: id,
          },
        },
        {
          withCredentials: true,
        }
      );
      // console.log("89", result.data);
      this.list1 = result.data.follow;
      this.list1.forEach((item) => {
        this.list2.push(item.userId);
      });
      this.list2.forEach(async (item) => {
        const res = await axios.get(
          "http://192.168.31.27:3000/user/event?" + this.param,
          {
            params: {
              uid: item,
              limit: 1,
            },
          },
          {
            withCredentials: true,
          }
        );
        // console.log("789", res);
        this.pic.push(res.data.events);
        // console.log(111, this.pic);
        if (this.pic.length == this.list1.length) {
          this.dfghbnjm();
        }
      });
    },
    dfghbnjm() {
      this.time = this.pic;
      this.hhh = false;
      for (var i = 0; i < this.time.length; i++) {
        var activeSubjectsObject = {};
        for (var j = 0; j < this.list1.length; j++) {
          if (i == j) {
            activeSubjectsObject.name = this.time[i];
            activeSubjectsObject.value = this.list1[j];
            this.one.push(activeSubjectsObject);
          }
        }
      }

      // console.log(this.one);
      for (i = 0; i < this.list1.length; i++) {
        // console.log(this.one[i]);
        if (this.one[i].name[0]) {
          this.one[i].name[0].json = JSON.parse(this.one[i].name[0].json);
        }
      }

      // console.log(this.one[0].name[0].json);
      for (let i = this.list1.length; i >= 0; i--) {
        // this.two.push(this.one[i]);
      }
    },
    // 调取接口获取用户等级
    async levels() {
      const res = await axios
        .get(
          "http://192.168.31.27:3000/song/detail?ids=1859603835&" + this.param,
          {
            withCredentials: true,
          }
        )
        .then((res) => {
          // console.log("等级", res);
          // if (lev == 0) {
          //   this.lev = false;
          // } else {
          //   this.lev = true;
          // }
        });
    },
  },
  created() {
    this.levels();
    this.user();
  },
  mounted() {},
  components: {},
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
}
.follow {
  padding-bottom: 200px;
  background-color: #928686;
}
/* 头部样式 */
.van-nav-bar {
  background-color: #928686;
}
.icon-gengduo1 {
  color: #fff;
}
.icon-jiahao2fill {
  color: #c2b0b0;
  line-height: 20px;
  font-size: 20px;
  height: 20px;
  width: 20px;
  background-color: #fff;
  border-radius: 20px;
}
/* 我的圈子 */
.follow .end {
  margin-top: 50px;
  font-size: 18px;
  color: #86e8f1;
  text-align: center;
}
.list {
  width: 500px;
  height: 70px;
  overflow-x: scroll;
  white-space: nowrap;
}
.follow-list {
  margin-top: 10px;
  height: 60px;
  display: flex;
  flex-wrap: nowrap;
}
.follow-list div {
  display: inline-block;
  /* float: left; */
}
.follow-list img {
  width: 45px;
  margin-left: 13px;
  border-radius: 45px;
  vertical-align: middle;
}
.icon-gengduo {
  margin-left: 16px;
  font-size: 45px;
  color: #a7a1a1;
  border-radius: 45px;
  background-color: #8a8280;
}
.follow-list p {
  text-align: center;
  line-height: 16px;
  color: #fff;
  font-size: 12px;
  margin-left: 16px;
  margin-top: 5px;
  width: 48px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
/* 我的关注 */
.follow-all {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid #807474;
}
.follow-all .head {
  height: 18px;
}
.follow .head {
  letter-spacing: 1px;
  padding: 0 14px;
}
.follow .head .left p {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.follow .head .right ul {
  display: flex;
  font-size: 13px;
  justify-content: space-around;
}
.follow .head .right ul li {
  font-size: 13px;
  color: #c3bfbe;
}
.follow .head .right ul .active {
  color: #fff;
  font-weight: 600;
}
.follow .zong .share {
  margin-top: 15px;
  margin-left: 15px;
}
.follow .zong .message {
  display: flex;
}
.follow .zong .message img {
  width: 40px;
  border-radius: 40px;
}
.follow .zong .message .name {
  line-height: 15px;
  margin-top: 3px;
  margin-left: 9px;
  font-size: 14px;
  color: #fff;
  letter-spacing: 1px;
  position: relative;
}
.follow .zong .message .name span {
  line-height: 12px;
}
.follow .zong .message .name img {
  /* vertical-align: middle; */
  margin-left: 2px;
  margin-right: 2px;
  height: 14px;
}
.follow .zong .message .name p {
  margin-top: 5px;
  color: #c5c1c0;
  font-size: 13px;
}
.follow-all .message .name .levels {
  position: absolute;
  right: 82px;
  top: 1px;
  font-size: 12px;
  color: #fce4e0;
  transform: scale(0.65);
}
.follow .follow-all .message .name .releaseTime {
  font-size: 12px;
  color: #c8c2c2;
}
.follow .follow-all .content {
  line-height: 18px;
  font-size: 13px;
  color: #fff;
  width: 245px;
  margin-top: 8px;
  margin-left: 50px;
  letter-spacing: 1px;
}
.follow .follow-all .content .icon-lianjie {
  margin-top: 3px;
  font-size: 14px;
  color: #86e8f1;
}
.follow .follow-all .content .icon-lianjie a {
  font-size: 14px;
  color: #86e8f1;
}
.follow .follow-all .content .picture {
  display: flex;
  flex-wrap: wrap;
  margin-top: 9px;
}
.follow-all .content img {
  width: 80px;
  height: 80px;
  margin-right: 1px;
  margin-bottom: 1px;
}
.follow-all .content img:nth-child(1) {
  border-radius: 10px 0 0 0;
}
.follow-all .content img:nth-child(3) {
  border-radius: 0 10px 0 0;
}
.follow-all .content img:nth-child(7) {
  border-radius: 0 0 0 10px;
}
.follow-all .content img:nth-child(9) {
  border-radius: 0 0 10px 0;
}
.follow-all .content .son {
  display: flex;
  background-color: #988c8c;
  margin-top: 9px;
  padding: 5px;
  border-radius: 10px;
}
.follow-all .content .son img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  margin-right: 5px;
}
.follow-all .content .son div p a {
  font-size: 12px;
  border: 1px solid #ad9f9f;
  padding: 2px;
  line-height: 12px;
  color: #ad9f9f;
  transform: scale(0.8);
  float: left;
}
.follow-all .content .son div p:nth-child(1) {
  line-height: 14px;
  font-size: 14px;
  float: left;
  width: 200px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.follow-all .content .son div p:nth-child(2) {
  margin-top: 5px;
  font-size: 12px;
  float: left;
  color: #dbd7d6;
}
.follow .friend {
  margin-top: 100px;
  margin-left: 90px;
  width: 250px;
  font-size: 50px;
}
</style>
